package uk.co.hs.domain.web;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.Index;
import org.hibernate.annotations.Type;

import uk.co.hs.domain.generic.UtilisoftGenericDomain;

@Entity
@org.hibernate.annotations.Table(appliesTo=WebRoleUrl.TABLE_NAME,
                                 indexes={@Index(name=WebRoleUrl.TABLE_NAME + "_IDX_1", columnNames={UtilisoftGenericDomain.PK, UtilisoftGenericDomain.VERSION}),
                                          @Index(name=WebRoleUrl.TABLE_NAME + "_IDX_2", columnNames=WebRoleUrl.ROLE_FK),
                                          @Index(name=WebRoleUrl.TABLE_NAME + "_IDX_3", columnNames=WebRoleUrl.URL_FK)})
@Table(name=WebRoleUrl.TABLE_NAME)
public class WebRoleUrl extends UtilisoftGenericDomain<Long>
{
  private static final long serialVersionUID = 1L;

  protected static final String TABLE_NAME = "WEB_ROLE_URL";
  protected static final String ROLE_FK = "ROLE_FK";
  protected static final String URL_FK = "URL_FK";

  private WebRole mRole;
  private WebUrl mUrl;
  private Boolean mEditable;

  public WebRoleUrl()
  {
    super();
  }

  public WebRoleUrl(WebRole aWebRole,
                    WebUrl aWebUrl,
                    Boolean aEditable)
  {
    super();
    setRole(aWebRole);
    setUrl(aWebUrl);
    setEditable(aEditable);
  }

  /**
   * Get Role.
   * @return Role.
   */
  @ManyToOne
  @JoinColumn(name=ROLE_FK)
  @NotNull
  @ForeignKey(name="WEB_ROLE_URL_TO_WEB_ROLE")
  public WebRole getRole()
  {
    return mRole;
  }

  /**
   * Set Role.
   * @param aRole Role.
   */
  public void setRole(WebRole aRole)
  {
    mRole = aRole;
  }

  /**
   * Get URL.
   * @return URL.
   */
  @ManyToOne
  @JoinColumn(name=URL_FK)
  @NotNull
  @ForeignKey(name="WEB_ROLE_URL_TO_WEB_URL")
  public WebUrl getUrl()
  {
    return mUrl;
  }

  /**
   * Set URL.
   * @param aUrl URL.
   */
  public void setUrl(WebUrl aUrl)
  {
    mUrl = aUrl;
  }

  /**
   * Is Editable.
   * @return Is Editable.
   */
  @Column(name="EDITABLE", nullable=false)
  @Type(type="true_false")
  public Boolean getEditable()
  {
    return mEditable;
  }

  /**
   * Set Editable.
   * @param aEditable Editable.
   */
  public void setEditable(Boolean aEditable)
  {
    mEditable = aEditable;
  }
}
